﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace PFMConfigurations
{
    public class ScheduleManager:ConfigurationManager<Schedule>

    {
        public ScheduleManager()
        {
            File = PFMGlobals.PFMDefinitions.CONFIGURATIONSDIR + "PFM-Schedule.XML";
        }
        public void Load()//从XML文件中读取
        {
            XmlTextReader myReader = new XmlTextReader(File);
            myReader.Read();
            List<Schedule> result = new List<Schedule>();
            Schedule aa = new Schedule();
            while (myReader.Read())
            {
                //如果是开始节点
                if (myReader.NodeType == XmlNodeType.Element)
                {
                    //通过myReader.Name得到节点名
                    string elementName = myReader.Name;
                    if (elementName == "Schedule")
                    {
                        aa = new Schedule();
                    }
                    //读取到Target元素 这时myReader.Read()读取到的内容为<Target>...</Target>
                    else if (elementName == "TargetID")
                    {
                        //读取到节点内文本内容
                        if (myReader.Read())
                        {
                            //通过myReader.Value获得文本内容
                            aa.TargetID = (new Guid(myReader.Value));

                        }
                    }
                    else if (elementName == "Time")
                    {
                        if (myReader.Read())
                        {
                            aa.Time = myReader.Value;

                        }
                    }
                    else if (elementName == "Interval")
                    {
                        if (myReader.Read())
                        {
                            string a = @myReader.Value;
                            aa.Interval = a;

                        }
                    }
                }
                else if (myReader.NodeType == XmlNodeType.EndElement)
                {
                    string elementName = myReader.Name;
                    if (elementName == "Schedule")
                    {
                        result.Add(aa);

                    }

                }
            }
            this.Items = result;

        }
       
    }
}
